<html>

<head>
    <script type="text/javascript" src="../../dist/ivank.js"></script>
    <script type="text/javascript">

        var balls = [];	// balls
        var dirs = [];	// directions
        var stage;
        var sprite;
        function Start() {
            stage = new ivank.Stage("c");

            var bitmapData = new ivank.BitmapData("night.jpg");
            bitmapData.loader.addEventListener('complete', () => {
                // background
                sprite=new ivank.DisplayObjectContainer();
                stage.addChild(sprite);

                var bg = new ivank.Bitmap(bitmapData);
                bg.width = stage.stageWidth ;
                bg.height = stage.stageHeight;
                console.log(bg.width, bg.height)
                bg.x = -bg.width / 2;
                bg.y = -bg.height / 2;
                sprite.x=bg.width/2;
                sprite.y=bg.height*0.8;
                sprite.addChild(bg);
                sprite.rotationX=-90;

                var bd = new ivank.BitmapData("ball.png");
                for (var i = 0; i < 100; i++) {
                    var b = new ivank.Bitmap(bd);
                    b.x = Math.random() * 900;
                    b.y = Math.random() * 500;
                    balls.push(b);
                    dirs.push({x:2 + Math.random() * 8, y:2 + Math.random() * 8,z:1});
                    stage.addChild(b);
                }
                stage.addEventListener(ivank.Event.ENTER_FRAME, onEF);
            })

        }

        function onEF(e) {
            //sprite&&sprite.rotationX++;
            var w = stage.stageWidth - 100;
            var h = stage.stageHeight - 300;
            for (var i = 0; i < balls.length; i++) {
                var b = balls[i], d = dirs[i];
                b.x += d.x; 
                b.y += d.y;
                //b.z += d.z;
                if (b.x < 0) d.x = Math.abs(d.x); if (b.x > w) d.x = -Math.abs(d.x);
                if (b.y < 0) d.y = Math.abs(d.y); if (b.y > h) d.y = -Math.abs(d.y);
            }
        }
    </script>
</head>

<body onload="Start();"><canvas id="c"></canvas></body>

</html>